<template>
  <van-dialog
    v-model="show"
    :show-confirm-button="false"
    :close-on-click-overlay="true"
    width="270px"
    @close="closeModal"
  >
    <div class="drawRecordModal">
      <div class="iconCon"><van-icon name="close" @click="closeModal" /></div>
      <div class="content">
        <div v-for="item in drawRecord" :key="item.id" class="listCon">
          <div>{{ item.prize.name }}</div>
          <div>{{ item.createTime | dateFilter }}</div>
        </div>
      </div>
      <div class="btnCon">
        <van-button
          :disabled="enrollMsg ? true : false"
          class="tipsBtn"
          round
          @click="fillMsgClick"
          >填写收货信息</van-button
        >
      </div>
    </div>
  </van-dialog>
</template>

<script>
import { Dialog, Button, Icon } from "vant";
import { formatDate } from "@/js/utils";
export default {
  components: {
    [Dialog.Component.name]: Dialog.Component,
    [Button.name]: Button,
    [Icon.name]: Icon,
  },
  props: {
    visible: {
      type: Boolean,
      default: false,
    },
  },
  data() {
    return {
      show: false,
    };
  },
  computed: {
    drawRecord() {
      return this.$store.state.activity.drawRecord.reverse();
    },
    enrollMsg() {
      return this.$store.state.activity.enrollMsg;
    },
  },
  watch: {
    visible: {
      immediate: true,
      handler(val) {
        this.show = val;
      },
    },
  },
  filters: {
    dateFilter(value) {
      let date = new Date(value);
      return formatDate(date, "yyyy-MM-dd");
    },
  },
  methods: {
    closeModal() {
      this.$emit("close-modal");
    },
    fillMsgClick() {
      this.$router.push({
        name: "fillMsg",
      });
    },
  },
};
</script>

<style lang="scss">
.drawRecordModal {
  padding: 40px 50px 36px 50px;
  .iconCon {
    text-align: right;
  }
  .content {
    padding: 12px;
    max-height: 40vh;
    overflow: auto;
  }
  .btnCon {
    text-align: center;
    padding-top: 24px;
  }
  .tipsBtn {
    background-image: linear-gradient(to right, #d45d60, #b60e11);
    color: white;
    width: 40vw;
    height: 100px;
  }
  .listCon {
    display: flex;
    padding: 24px 0;
    line-height: 1;
    justify-content: space-between;
  }
}
</style>